"use strict";
cc._RF.push(module, '213999iiyBMhYR0DPbC3iSF', 'MatchCarView');
// scripts/MatchCarView.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("GlobalUserData"),
    s = t("GameConstant"),
    l = t("CarRoleView"),
    c = t("Util"),
    d = t("AssemblyItem"),
    h = t("CarConstant"),
    p = t("HallConstant"),
    u = cc._decorator,
    f = u.ccclass,
    m = u.property,
    _ = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.pfb_role = null, e.pfb_assembly = null, e.roleControl = null, e.equipBodyData = null, e.equipWheelData = [], e.equipWeaponData = [], e.equipToolsData = [], e.equipCarBody = null, e.equipCarWheel = [null, null], e.equipCarWeapon = [null, null], e.equipCarTools = [null, null], e.equipWheelRadius = 0, e._nCarIndex = 0, e.assemblyNode = null, e.isShown = !1, e;
  }

  return n(e, t), e.prototype.init = function (t, e) {
    void 0 === e && (e = !1), this._nCarIndex = t, this._isEnemy = e;
    var o = c.Util.getBodyData(r["default"].curEquipBody[this._nCarIndex]);
    this.node.active = null != o, o && (this.createRole(), this.createCarBody(), this.createCarWheel(), this.createCarWeapon(), this.createCarTools(), e ? this.setColorRecur(this.node, cc.Color.BLACK) : r["default"].nGuideStep >= p.Guide_Step.trySuperCar && (this.assemblyNode || (this.assemblyNode = this.node.getChildByName("assembly"), this.assemblyNode.active = !1)));
  }, e.prototype.setColorRecur = function (t, e) {
    for (var o = 0; o < t.children.length; o++) {
      var i = t.children[o];
      i.color = e, this.setColorRecur(i, e);
    }
  }, e.prototype.createRole = function () {
    var t = c.Util.getBodyId(r["default"].curEquipBody[this._nCarIndex]);

    if (t) {
      if (!this.roleControl) {
        var e = cc.instantiate(this.pfb_role);
        this.node.addChild(e), this.roleControl = e.getComponent(l["default"]);
      }

      this.roleControl.init(this, s.Physics_Car_Tag.Left, t);
    }
  }, e.prototype.createCarBody = function () {
    var t = c.Util.getBodyData(r["default"].curEquipBody[this._nCarIndex]);

    if (this.equipBodyData = t, !this.equipCarBody) {
      var e = cc.instantiate(this.pfb_assembly);
      this.node.addChild(e), this.equipCarBody = e.getComponent(d.AssemblyItem);
    }

    var o = !!r["default"].curEquipWheel[this._nCarIndex][0],
        i = !!r["default"].curEquipWheel[this._nCarIndex][0];
    this.equipCarBody.updateItem(null, !0, 0, this.equipBodyData, !1, d.Assembly_Type.SuperCar, o, i);
  }, e.prototype.createCarWheel = function () {
    for (var t = 0; t < r["default"].curEquipWheel[this._nCarIndex].length; t++) {
      var e = c.Util.getWheelData(r["default"].curEquipWheel[this._nCarIndex][t]);

      if (e) {
        this.equipWheelData[t] = e, this.equipWheelRadius = this.equipWheelRadius < e.radius && e.radius;
        var o = void 0;
        this.equipCarWheel[t] ? o = this.equipCarWheel[t].node : (o = cc.instantiate(this.pfb_assembly), this.node.addChild(o, 20), this.equipCarWheel[t] = o.getComponent(d.AssemblyItem)), o.position = h.GetCarBodyData(c.Util.getBodyId(r["default"].curEquipBody[this._nCarIndex])).wheelPos[t], this.showShadow(h.GetCarBodyData(c.Util.getBodyId(r["default"].curEquipBody[this._nCarIndex])).wheelPos[t]), this.equipCarWheel[t].updateItem(null, !0, 0, e, !1, d.Assembly_Type.SuperCar);
      } else this.equipWheelData[t] = null, this.equipCarWheel[t] && this.equipCarWheel[t].node.destroy(), this.equipCarWheel[t] = null;
    }
  }, e.prototype.createCarWeapon = function () {
    for (var t = 0; t < r["default"].curEquipWeapon[this._nCarIndex].length; t++) {
      var e = c.Util.getWeaponData(r["default"].curEquipWeapon[this._nCarIndex][t]);

      if (e) {
        this.equipWeaponData[t] = e;
        var o = void 0;
        this.equipCarWeapon[t] ? o = this.equipCarWeapon[t].node : (o = cc.instantiate(this.pfb_assembly), this.node.addChild(o, 30), this.equipCarWeapon[t] = o.getComponent(d.AssemblyItem)), o.position = h.GetCarBodyData(c.Util.getBodyId(r["default"].curEquipBody[this._nCarIndex])).weaponPos[t], this.equipCarWeapon[t].updateItem(null, !0, 0, e, !1, d.Assembly_Type.SuperCar);
      } else this.equipWeaponData[t] = null, this.equipCarWeapon[t] && this.equipCarWeapon[t].node.destroy(), this.equipCarWeapon[t] = null;
    }
  }, e.prototype.createCarTools = function () {
    for (var t = 0; t < r["default"].curEquipTools[this._nCarIndex].length; t++) {
      var e = c.Util.getToolsData(r["default"].curEquipTools[this._nCarIndex][t]);

      if (e) {
        this.equipToolsData[t] = e;
        var o = void 0;
        this.equipCarTools[t] ? o = this.equipCarTools[t].node : (o = cc.instantiate(this.pfb_assembly), this.node.addChild(o, 40), this.equipCarTools[t] = o.getComponent(d.AssemblyItem)), o.position = h.GetCarBodyData(c.Util.getBodyId(r["default"].curEquipBody[this._nCarIndex])).toolsPos[t], this.equipCarTools[t].updateItem(null, !0, 0, e, !1, d.Assembly_Type.SuperCar);
      } else this.equipToolsData[t] = null, this.equipCarTools[t] && this.equipCarTools[t].node.destroy(), this.equipCarTools[t] = null;
    }
  }, e.prototype.showShadow = function (t) {
    var e = this;
    this.isShown || this._isEnemy || (this.isShown = !0, this.scheduleOnce(function () {
      e.assemblyNode && (e.assemblyNode.active = !0, e.assemblyNode.y = t.y - 50);
    }, .2));
  }, a([m(cc.Prefab)], e.prototype, "pfb_role", void 0), a([m(cc.Prefab)], e.prototype, "pfb_assembly", void 0), a([f], e);
}(cc.Component);

o["default"] = _;

cc._RF.pop();